package com.sensePlusVR.adapter;

import java.util.List;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sensePlusVR.activity.mine.FeedbackDetailActivity;
import com.sensePlusVR.adapter.NotifiSettingAdapter.NotifyViewHolder;
import com.sensePlusVR.bean.FeedbackListRespDto;
import com.sensePlusVR.bean.FeedbackReplyItem;
import com.sensePlusVR.main.R;
import com.sensePlusVR.utils.Constant;
import com.sensePlusVR.utils.DateTimeUtil;
import com.sensePlusVR.utils.MyLog;
import com.sensePlusVR.utils.MyPageJump;
/**
 * 
 * @author: Loren
 * @create: 2016-8-10下午2:53:26
 * @desc: notification adapter
 *
 */
public class NotifiSettingAdapter extends
		RecyclerView.Adapter<NotifyViewHolder>{
	private static final String TAG = NotifiSettingAdapter.class.getSimpleName();
	private Context context;
	private List<FeedbackListRespDto> notifiList;

	public NotifiSettingAdapter(Context context,
			List<FeedbackListRespDto> notifiList) {
		this.context = context;
		this.notifiList = notifiList;
	}

	@Override
	public NotifyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		View view = LayoutInflater.from(context).inflate(
				R.layout.activity_settting_notification_item, parent, false);
		return new NotifyViewHolder(view);
	}

	@Override
	public void onBindViewHolder(NotifyViewHolder holder, int position) {
		FeedbackListRespDto feedbackListRespDto = notifiList.get(position);
		MyLog.d(TAG, "list size : " + notifiList.size());
		FeedbackReplyItem feedbackReplyItem = feedbackListRespDto.getFeedbackReplyList().get(0);
		
		holder.setting_notifi_item_time.setText(DateTimeUtil.getStandTime(feedbackReplyItem.getCreateTime()));
		holder.setting_notifi_item_content.setText(feedbackReplyItem.getContent());
		
		
		
		holder.setting_root_linear.setOnClickListener(new MyOnClickListener(holder, position));
		holder.setting_notifi_item_title.setOnClickListener(new MyOnClickListener(holder, position));
		holder.setting_notifi_item_time.setOnClickListener(new MyOnClickListener(holder, position));
	}
	
	@SuppressWarnings("unused")
	public class MyOnClickListener implements View.OnClickListener {
		private NotifyViewHolder holder;
		private FeedbackListRespDto feedbackListRespDto;
		private int position;

		public MyOnClickListener(NotifyViewHolder holder, int position) {
			this.holder = holder;
			this.position = position;
			if(position<notifiList.size()){
				this.feedbackListRespDto = notifiList.get(position);
			}
		}

		@Override
		public void onClick(View v) {
			MyLog.d(TAG, "onclick position : " + position);
			switch (v.getId()) {
			case R.id.setting_root_linear:
				//MyToast.showMessage(context, "setting_root_linear");
				MyPageJump.pageJumpAddInt(context, FeedbackDetailActivity.class, Constant.INTENT_FEEDBACK_FEEDBACKID, feedbackListRespDto.getId());
				break;
			case R.id.setting_notifi_item_title:
				break;
			case R.id.setting_notifi_item_time:
				break;
			}
		}
	}

	@Override
	public int getItemCount() {
		return notifiList != null ? notifiList.size() : 0;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public class NotifyViewHolder extends RecyclerView.ViewHolder {
		public TextView setting_notifi_item_title;
		public TextView setting_notifi_item_time;
		public TextView setting_notifi_item_content;
		public TextView delete;
		public LinearLayout layout;
		public LinearLayout setting_root_linear;

		public NotifyViewHolder(View itemView) {
	        super(itemView);
	        setting_notifi_item_title = (TextView) itemView.findViewById(R.id.setting_notifi_item_title);
	        setting_notifi_item_time = (TextView) itemView.findViewById(R.id.setting_notifi_item_time);
	        setting_notifi_item_content = (TextView) itemView.findViewById(R.id.setting_notifi_item_content);
	        delete = (TextView) itemView.findViewById(R.id.item_delete);
	        layout = (LinearLayout) itemView.findViewById(R.id.item_layout);
	        setting_root_linear = (LinearLayout) itemView.findViewById(R.id.setting_root_linear);
	        
	    }
	}
	
	public void removeItem(int position) {
		notifiList.remove(position);
		notifyDataSetChanged();
	}
	
	public void refreshData(List<FeedbackListRespDto> feedbackListRespDtos) {
		MyLog.d(TAG, "refreshData...feedbackListRespDtos size : " + feedbackListRespDtos.size());
		notifyDataSetChanged();
	}
}
